<template>
  <!-- <button type="button" :class="['el-button', 'el-button--' + type]"> -->
  <!-- <button type="button" :class="['el-button', 'el-button--' +  type ? type : 'default' ]"> -->
  <button
    @click="$emit('click', $event)"
    :autofocus="autofocus"
    :type="nativeType"
    :disabled="loading"
    :class="[
      'el-button',
      'el-button--' + (type || 'default'),
      size && 'el-button--' + size,
      {
        // 当值是 true 的时候会把 key 当做 class
        'is-plain': plain,
        'is-round': round,
        'is-circle': circle,
        'is-disabled': disabled,
        'is-loading': loading,
      },
    ]"
  >
    <div v-if="loading" class="el-icon-loading"></div>
    <!-- //!#1 如果传递了 icon 属性，这儿会多一个 i 标签，并且把 icon 的值当做 i 标签 class 的值 -->
    <i v-if="icon && !loading" :class="icon"></i>
    <!-- 挖个坑 -->
    <!-- //!#2 如果传默认插槽了才需要 span 展示 -->
    <span v-if="$slots.default"><slot /></span>
  </button>
</template>
<script>
export default {
  name: "ElButton",
  props: {
    type: {
      type: String,
      // default: 'default'
    },
    plain: {
      type: Boolean,
      default: false,
    },
    round: {
      type: Boolean,
      default: false,
    },
    circle: {
      type: Boolean,
      default: false,
    },
    icon: String,
    disabled: {
      type: Boolean,
      default: false,
    },
    loading: {
      type: Boolean,
      default: false,
    },
    size: String,
    autofocus: {
      type: Boolean,
      default: false,
    },
    nativeType: {
      type: String,
      default: 'button'
    }
  },
  created() {
    // 它是一个对象，里面包含了所有的插槽信息
    // console.log(this.$slots)
  },
};
</script>